/**
 * 	 * @author  Rooike
 * 请求数据处理
 * @param string url 请求地址
 * @param string method 请求方式 (默认是 get )
 *  GET or POST
 * @param {*} postData 请求参数
 * @param bool isForm 数据格式
 *  true: 'application/x-www-form-urlencoded'
 *  false:'application/json'
 * @param bool hideLoading 是否隐藏loading
 *  true: 隐藏
 *  false:显示
 */
const baseUrl = 'http://gy.hyq.ink/';
var zheader = {};

const setToken = function () {
	var token = uni.getStorageSync('token');
	zheader ={
		'content-type': 'application/x-www-form-urlencoded',
		'token': token ? token : ''
	}
}
export const post = (url = '', date = {}, type = 'post') => {
	setToken();
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: date,
			header: zheader,
			dataType: 'json',
		}).then((response) => {
			setTimeout(function() {
				uni.hideLoading();
			}, 200);
			let [error, res] = response;
			resolve(res.data);
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
	});
}

export const get = (url = '', date = {}, type = 'GET') => {
	setToken();
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: date,
			header: header,
			dataType: 'json',
		}).then((response) => {
			setTimeout(function() {
				uni.hideLoading();
			}, 200);
			let [error, res] = response;
			resolve(res.data);
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
	});
}
// export default http
